﻿@inherits AdminCompontentBase
<div @ref="Ref">
    <DefaultSheetDialog Value="@_visible" ValueChanged="HandleVisibleChanged" Title="@T("Permission.EditOrdinaryMessage")">
        <ChildContent>
            <MForm Model="_model" EnableValidation EnableI18n @ref="_form" Class="full-height mt-n2 pt-3">
                <MStepper Value="_model.Step" Elevation=0 Class="d-flex flex-column full-height">
                    <MStepperHeader Class="ma-n6" Style="box-shadow:none !important">
                        <MStepperStep Step="1" Complete="_model.Step>1">
                            @T("DisplayName.MessageInfoContent")
                        </MStepperStep>
                        <MDivider></MDivider>
                        <MStepperStep Step="2" Complete="_model.Step>2">
                            @T("DisplayName.MessageTaskReceiver")
                        </MStepperStep>
                        <MDivider></MDivider>
                        <MStepperStep Step="3">
                            @T("DisplayName.MessageTaskSendingRule")
                        </MStepperStep>
                    </MStepperHeader>
                    <MStepperItems Class="flex-grow-1">
                        <MStepperContent Class="full-height pa-0" Step="1">
                            <AutoHeight Overflow AutoClass="form-content">
                                <AutoHeightContent>
                                    <SSelect @bind-Value="@_model.ChannelType"
                                             Items="@(GetEnumList<ChannelTypes>().Where(x=>x!=ChannelTypes.Sms).ToList())"
                                             Label="@T("DisplayName.ChannelType")"
                                             ItemText="item => T(item.ToString())"
                                             ItemValue="item => item"
                                             TItem="ChannelTypes"
                                             TItemValue="ChannelTypes"
                                             TValue="ChannelTypes?"
                                             OnSelectedItemUpdate="HandleChannelTypeChangeAsync">
                                    </SSelect>
                                    <SSelect @bind-Value="_model.ChannelId"
                                             Items="@_channelItems"
                                             Label="@T("DisplayName.Channel")"
                                             ItemText="item => item.DisplayName"
                                             ItemValue="item => item.Id">
                                    </SSelect>
                                    @if (_model.ChannelType == ChannelTypes.App)
                                    {
                                        <div class="d-flex">
                                            <SCheckbox Value="true" Disabled Label="@T("NotificationMessage")"></SCheckbox>
                                            <SCheckbox @bind-Value="_model.ExtraProperties.IsWebsiteMessage" Class="ml-6" Label="@T("InAppMessages")" Tooltip="@T("InAppMessagesTips")"></SCheckbox>
                                        </div>
                                    }
                                    @if (_model.ChannelType == ChannelTypes.WeixinWork)
                                    {
                                        <SSelect @bind-Value="@_model.MessageInfo.Type"
                                                 Items="@(GetEnumList<WeixinWorkTemplateTypes>())"
                                                 Label="@T("TemplateType")"
                                                 ItemText="item => T(item.ToString())"
                                                 ItemValue="item => (int)item"
                                                 TItem="WeixinWorkTemplateTypes"
                                                 TItemValue="int"
                                                 TValue="int" OnChange="HandleSelectTemplateType">
                                        </SSelect>
                                    }
                                    @if (_model.ComputedTitleShow)
                                    {
                                        <STextField @bind-Value="_model.MessageInfo.Title"
                                                    Label="@T("DisplayName.MessageInfoTitle")">
                                        </STextField>
                                    }
                                    <div>
                                        @if (_model.ComputedMarkdown)
                                        {
                                            <DefaultMarkdown @bind-Html="_model.MessageInfo.Content" @bind-Value="_model.MessageInfo.Markdown" Style="height:400px"></DefaultMarkdown>
                                            <MInput @bind-Value="_model.MessageInfo.Content" />
                                        }
                                        else
                                        {
                                            <STextarea @bind-Value="_model.MessageInfo.Content"
                                                       Label="@T("DisplayName.MessageInfoContent")">
                                            </STextarea>
                                        }
                                    </div>
                                    @if (_model.ComputedJumpUrlShow)
                                    {
                                        <STextField @bind-Value="_model.MessageInfo.JumpUrl"
                                                    Label="@T("DisplayName.MessageTemplateJumpUrl")" Tooltip="@T("JumpUrlTips")">
                                            <PrependContent>
                                                <MCheckbox Class="mt-0" @bind-Value="_model.MessageInfo.IsJump" TValue="bool" Readonly="_model.ComputedJumpUrlRequired"></MCheckbox>
                                            </PrependContent>
                                        </STextField>
                                    }
                                    @if (_model.ChannelType == ChannelTypes.Sms)
                                    {
                                        <STextField @bind-Value="_model.Sign"
                                                    Label="@T("DisplayName.MessageTemplateSign")">
                                        </STextField>
                                    }
                                    @if (_model.ChannelType == ChannelTypes.App)
                                    {
                                        <ExtraProperties @bind-Value="_model.MessageInfo.ExtraProperties"></ExtraProperties>
                                        <MExpansionPanels Accordion Flat>
                                        <MExpansionPanel>
                                            <MExpansionPanelHeader Context="PanelHeader" Class="pa-0">
                                                <DefaultSubTitle Class="">@T("OptionalConfiguration")</DefaultSubTitle>
                                            </MExpansionPanelHeader>
                                            <MExpansionPanelContent Class="pa-0">
                                                <DefaultSubTitle Class="mb-6">Android</DefaultSubTitle>
                                                <STextField @bind-Value="_model.ExtraProperties.IntentUrl"
                                                            Label="@T("IntentUrl")">
                                                    <AppendOuterContent>
                                                        <MenuTooltip Class="ml-2" Tooltip="@T("IntentUrlTips")" />
                                                    </AppendOuterContent>
                                                </STextField>
                                                <DefaultSubTitle Class="my-6">Ios</DefaultSubTitle>
                                                <MRadioGroup @bind-Value="_model.ExtraProperties.IsApnsProduction" Row>
                                                    <MRadio Label="@T("development")"
                                                            Value="false">
                                                    </MRadio>
                                                    <MRadio Label="@T("production")"
                                                            Value="true">
                                                    </MRadio>
                                                </MRadioGroup>
                                            </MExpansionPanelContent>
                                        </MExpansionPanel>
                                    </MExpansionPanels>
                                    }
                                </AutoHeightContent>
                                <FooterContent>
                                    <div class="d-flex mt-6">
                                        <MSpacer></MSpacer>
                                        <SButton Medium OnClick="async() => await Throttle(HandleSaveAsync)" Outlined>@T("Save")</SButton>
                                        <SButton Medium OnClick="()=> HandleNextStep()" Class="ml-6">@T("NextStep")</SButton>
                                    </div>
                                </FooterContent>
                            </AutoHeight>
                        </MStepperContent>
                        <MStepperContent Class="full-height pa-0" Step="2">
                            <AutoHeight Overflow>
                                <AutoHeightContent>
                                    @if (_model.ComputedBroadcast && !_selectReceiverType)
                                    {
                                        <ReceiverTypeSelect @bind-value="_model.ReceiverType" OnClick="HandleReceiverType" />
                                    }
                                    else
                                    {
                                        <MInput @bind-Value="_model.Receivers" />
                                        <MessageReceivers @bind-ReceiverType="_model.ReceiverType"
                                                      @bind-SelectReceivers="_selectReceivers"
                                                      @bind-ImportReceivers="_importReceivers"
                                                      @bind-SelectReceiverType="_model.SelectReceiverType"
                                                      ChannelType="_model.ChannelType" />
                                    }
                                </AutoHeightContent>
                                <FooterContent>
                                    <div class="d-flex mt-6">
                                        <MButton Icon OnClick="HandleReceiverBack">
                                            <SIcon Size="24" Color="emphasis2">mdi-keyboard-backspace</SIcon>
                                        </MButton>
                                        <MSpacer />
                                        @if (_model.ChannelType != ChannelTypes.WebsiteMessage || _selectReceiverType)
                                        {
                                            <SButton Medium OnClick="async() => await Throttle(HandleSaveAsync)" Outlined>@T("Save")</SButton>
                                            <SButton Medium Class="ml-6" OnClick="()=> HandleNextStep()">@T("NextStep")</SButton>
                                        }
                                    </div>
                                </FooterContent>
                            </AutoHeight>
                        </MStepperContent>
                        <MStepperContent Class="full-height pa-0" Step="3">
                            <AutoHeight Overflow>
                                <AutoHeightContent>
                                    <MInput @bind-Value="_model.SendRules" />
                                    <MessageSendingRules Class="mt-2" @bind-Value="_model.SendRules" />
                                </AutoHeightContent>
                                <FooterContent>
                                    <div class="d-flex mt-6">
                                        <MButton Icon OnClick="HandleSendingRuleBack">
                                            <SIcon Size="24" Color="emphasis2">mdi-keyboard-backspace</SIcon>
                                        </MButton>
                                        <MSpacer />
                                        <SButton Medium OnClick="async() => await Throttle(HandleSaveAsync)" Outlined>@T("Save")</SButton>
                                        <SButton Medium Class="ml-6" OnClick="async() => await Throttle(HandleSendAsync)">@T("SaveSend")</SButton>
                                    </div>
                                </FooterContent>
                            </AutoHeight>
                        </MStepperContent>
                    </MStepperItems>
                </MStepper>
            </MForm>
        </ChildContent>
    </DefaultSheetDialog>
</div>